package cn.alise.qdp.service.gov;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import cn.alise.qdp.mapper.gov.GovAreaInfoMapper;
import cn.alise.qdp.model.gov.GovAreaInfo;

@Service
@Transactional(rollbackFor = Exception.class)
public class GovAreaInfoService {
	
	@Resource(name = "govAreaInfoMapper")
	private GovAreaInfoMapper govAreaInfoMapper;
	
	/**
	 * 查询指定地区下的所有数据
	 * @param map
	 * @return
	 */
	public List<GovAreaInfo> getChildren(String parentId) {
		GovAreaInfo area = new GovAreaInfo();
		area.setParentId(parentId);
		
		return this.selectAll(area);
	}
	
	/**
	 * 查询详细信息
	 * @param areaCode
	 * @return
	 */
	public GovAreaInfo getArea(String areaCode) {
		GovAreaInfo area = new GovAreaInfo();
		area.setAreaCode(areaCode);
		
		List<GovAreaInfo> ret = this.selectAll(area);
		if (!CollectionUtils.isEmpty(ret)) {
			return ret.get(0);
		} else {
			return null;
		}
	}
	
	/**
	 * 查询区域信息
	 * @param area
	 * @return
	 */
	public List<GovAreaInfo> selectAll(GovAreaInfo area) {
		return this.govAreaInfoMapper.selectAll(area);
	}
}
